<template>
    <div>
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">硕士学位申请系统</el-breadcrumb-item>
            <el-breadcrumb-item>答辩结果批复</el-breadcrumb-item>
        </el-breadcrumb>
        <el-table :data="students" style="width: 100%">
            <el-table-column prop="studentId" label="学号"></el-table-column>
            <el-table-column prop="name" label="姓名"></el-table-column>
            <el-table-column prop="paperName" label="论文中文标题"></el-table-column>
            <el-table-column prop="reviewAsis" label="答辩秘书"></el-table-column>
            <el-table-column prop="reviewType" label="答辩形式"></el-table-column>
            <el-table-column label="处理">
                <template slot-scope="scope">
                    <el-radio-group v-model="scope.row.result" @change="handleStatusChange(scope.row)">
                        <el-radio label="agree">同意</el-radio>
                        <el-radio label="disagree">不同意</el-radio>
                    </el-radio-group>
                </template>
            </el-table-column>
            <el-table-column>
                <template slot-scope="scope">
                    <el-button @click="handleProcess(scope.row)">确认</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>

<script>
import axios from "axios";

export default {
    data() {
        return {
            students: [
                {
                    studentId: '001',
                    name: '张三',
                    paperName: '论文1',
                    reviewAsis: 'A001',
                    reviewType: '线下',
                    result: '',
                },
            ]
        };
    },
    methods: {
        getPageList() {
            axios({
                url: `http://localhost:8888/defence/reply/pageList`,
                method: 'get',
                responseType: 'json',
            }).then(res => {
                console.log(res);
                const students = res.data.data.records;
                this.students = students;
            }).catch(err => {
                console.log(err)
            })
        },
        handleProcess(student) {
            根据学生的状态调用后端接口修改论文状态
            if (student.result === 'agree') {
                this.updatePaperStatus(student.studentId, 'agree');
            } else if (student.result === 'disagree') {
                this.updatePaperStatus(student.studentId, 'disagree');
            }
        },
        updatePaperStatus(studentId, result) {
            // 调用后端接口来更新学生的论文状态
            // 发起 HTTP 请求，传递学生的 ID 和状态给后端
            // 示例中使用了 axios 库来发送 HTTP 请求，你可以根据自己的实际情况使用相应的库或方法
            // 处理成功响应，并显示修改成功的提示框
            axios({
                url: `http://localhost:8888/blind/info/edit/${studentId}`,
                method: 'put',
                data: {
                    result: result === 'agree' ? '同意' : '不同意'
                }
            }).then(res => {
                console.log(res);
                this.$message.success('更新成功');
            }).catch(err => {
                console.log(err);
                this.$message.error('出错了！');
            })
        },
    },
    mounted() {
        this.getPageList();
    }
};
</script>
